<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\RoomPresetRequest;
use App\CustHub\Service\ChRoomPresetService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: 'ch/room/preset'),ApiAuth,VerifySignature]
class RoomPresetController extends BaseController
{
    #[Inject]
    protected ChRoomPresetService $service;

    /**
     * 获取方案列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping("list")]
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getPageList($this->request->all(),false));
    }

    /**
     * 保存方案
     * @param RoomPresetRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping("save")]
    public function save(RoomPresetRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取方案信息
     * @param RoomPresetRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getInfo')]
    public function getInfo(RoomPresetRequest $request)
    {
        return $this->success($this->service->read($request->input('id')));
    }

    #[PostMapping("update")]
    public function update(RoomPresetRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->update($this->request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除方案
     * @param RoomPresetRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(RoomPresetRequest $request)
    {
        $ids = json_decode($request->input('ids'),true);
        return $this->service->delete($ids) ? $this->success() : $this->error();
    }
}